import apiClient from './client'
import type { Stock } from '@/types/product'

export interface StockQuantityParams {
  shoeId: number
  sizeId: number
  colorId: number
}

export const stockService = {
  // 查询库存（按鞋/尺码/颜色） GET /api/v1/stock/quantity
  getQuantity: ({ shoeId, sizeId, colorId }: StockQuantityParams) =>
    apiClient.get<Stock>('/api/v1/stock/quantity', {
      params: { shoeId, sizeId, colorId },
    }),

  // 增加库存（按鞋/尺码/颜色） POST /api/v1/stock/increase
  increase: ({ shoeId, sizeId, colorId }: StockQuantityParams, stockQuantity: number) =>
    apiClient.post<boolean>('/api/v1/stock/increase', undefined, {
      params: { shoeId, sizeId, colorId, stockQuantity },
    }),

  // 检查库存并扣减（按鞋/尺码/颜色） POST /api/v1/stock/check-and-decrease
  checkAndDecrease: ({ shoeId, sizeId, colorId }: StockQuantityParams, quantity: number) =>
    apiClient.post<boolean>('/api/v1/stock/check-and-decrease', undefined, {
      params: { shoeId, sizeId, colorId, quantity },
    }),
}

export default stockService


